package com.afd.ozblip.share;

import android.content.Context;

import com.afd.ozblip.util.AsyncAction;
import com.afd.ozblip.util.AsyncLoadData;
import com.tencent.weibo.api.TAPI;
import com.tencent.weibo.constants.OAuthConstants;
import com.tencent.weibo.oauthv2.OAuthV2;
import com.tencent.weibo.oauthv2.OAuthV2Client;

public class ShareAction {

	/**
	 * 发送微博到QQ
	 * 
	 * @param oAuthV2
	 * @param content
	 *            内容
	 * @param picPath
	 *            图片地址
	 */
	public static void shareWithImgToQQ(Context context, String shareContent,
			String picPath) {
		OAuthV2 oAuth = new OAuthV2(ShareConfig.QQ_Redirect_Uri);
		oAuth.setClientId(ShareConfig.QQ_App_Key);
		oAuth.setClientSecret(ShareConfig.QQ_App_Seret);
		OAuth oauth = TokenStore
				.fetchOAuth(context, ShareConfig.SHARE_WEIBO_QQ);
		OAuthV2Client.parseAccessTokenAndOpenId(oauth.getResponseData(), oAuth);
		// 关闭OAuthV2Client中的默认开启的QHttpClient。
		OAuthV2Client.getQHttpClient().shutdownConnection();
		TAPI tAPI = new TAPI(OAuthConstants.OAUTH_VERSION_2_A);

		try {
			String content = "";
			if (shareContent.length() > ShareConfig.QQ_Text_Limit) {
				content = shareContent.substring(0, ShareConfig.QQ_Text_Limit);
			} else {
				content = shareContent;
			}
			tAPI.addPic(oAuth, "json", content, "127.0.0.1", picPath);
		} catch (Exception e) {
			e.printStackTrace();
		}
		tAPI.shutdownConnection();
	}
}
